using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace MTRC.ODMS.Web.SOM.CodeSetup
{
    /// <summary>
    /// Author:SQB
    /// </summary>
    /// 

    public partial class FireZoneGroupList : BasePage_SOM
    {

        #region MenuID

        protected override string MenuID
        {
            get
            {
                return "M140809";
            }
        }

        #endregion

        #region Page Init And Load

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            this.ChangeLanguage += new ChangeLanguageEventHandler(SetLanguage_Click);
        }

        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // add by dylan 20151030 for u275.1 
                this.grvData.PageSize = this.GridViewPageDefaultSize();
                SetLanguage();
            }
        }

        private void SetLanguage()
        {
            this.lbl_CodeSetupTitle.Text = this.GetLabel("SOM_CodeSetupFireZoneGroupList");
            this.lblFireLink.Text = this.GetLabel("SOM_FireSystem", true);
            this.lblZoneGroup.Text = this.GetLabel("SOM_FireLinkZoneGroup", true);
            this.lblObsolete.Text = GetLabel("COM_Show", true);
            this.chkVoid.Text = this.GetLabel("SOM_Voided");
            this.btnSearch.Text = this.GetLabel("COM_Search");
            this.btnAddNew.Text = this.GetLabel("SOM_AddNewAssetLoanItem");
            BindFireLink();
            BindData();
        }

        /// <summary>
        /// Bind drop down list FireLink
        /// </summary>
        private void BindFireLink()
        {
            //update by gordon 20151026 U247
            //DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDFireZoneGrp.GetCurrentLocationAndUnVoidFireZoneGrp(this.ODMUser.StationID);
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDFireZoneGrp.GetCurrentLocationAndUnVoidFireZoneGrp(this.ODMUser.LocationID);
            BindListControl(this.ddlFireLink, "FireLinkID", "FireLinkCode", dt, true);

            dt.Dispose();
            dt = null;
        } 

        private void BindData()
        {
            //update by gordon 20151026 U247
            //DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDFireZoneGrp.GetFireZoneGrpByFireLinkAndZoneGroup(int.Parse(this.ddlFireLink.SelectedValue), this.txtZoneGroup.Text.Trim(),this.ODMUser.StationID,this.chkVoid.Checked);
            DataTable dt = MTRC.ODMS.DAL.SOM.CodeSetup.CDFireZoneGrp.GetFireZoneGrpByFireLinkAndZoneGroup(int.Parse(this.ddlFireLink.SelectedValue), this.txtZoneGroup.Text.Trim(), this.ODMUser.LocationID, this.chkVoid.Checked);
            this.grvData.DataSource = dt.DefaultView;
            this.grvData.DataBind();
        }

        protected void grvData_NeedDataBind()
        {
            BindData();
        }

        protected void grvData_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ((HyperLink)e.Row.Cells[5].FindControl("hypEdit")).NavigateUrl = "FireZoneGroupEntry.aspx?FireZoneGrpID=" + this.grvData.DataKeys[e.Row.RowIndex]["FireZoneGrpID"].ToString();
                ((HyperLink)e.Row.Cells[5].FindControl("hypEdit")).ToolTip = this.GetLabel("SOM_ZoneGroupEntry");
                ////e.Row.Cells[3].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[3].Text), true);//huangyao 20090119: fixed TD: 1124
                ////e.Row.Cells[4].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[4].Text), true);//huangyao 20090119: fixed TD: 1124  
                e.Row.Cells[3].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[3].Text), false);//huangyao 20090119: fixed TD: 1124
                e.Row.Cells[4].Text = this.FormatDateTime(DateTime.Parse(e.Row.Cells[4].Text), false);//huangyao 20090119: fixed TD: 1124
            }
        }

        void SetLanguage_Click(object sender, EventArgs e)
        {
            SetLanguage();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            this.Response.Redirect("FireZoneGroupEntry.aspx");
        }
    }
}
